package org.spring.boot.jdbctemplate.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.boot.jdbctemplate.util.AbstractGeneration;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

/**
 * @author: eastcom
 * @desc: 代维驻点信息
 **/
@Service
public class GenerationArrestpiontService extends AbstractGeneration {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	public void run() {
		/* 根据文件名称下载文件到本地 */
		String fileName = "D:\\njy\\组巡指标2018102111-高铁小区纬度（error）.csv";
		this.logger.info("analyse file name is {} start", fileName);
		File file = new File(fileName);

		/* 解析文件并入库 */
		try{
			List<String[]> paraseList = super.parase(file);
			if(paraseList.size() == 0){
				return;
			}
			save(paraseList);
		}catch (Exception e){
			this.logger.info("GenerationArrestpiontService error is {}", e.getMessage());
		}
		this.logger.info("GenerationArrestpiontService end");
	}

	@Override
	public void save(List<String[]> list) throws Exception {
		int[][] saveSizeArray = super.getGenerationDao().saveArrestpiont(list);
		this.logger.info("GenerationArrestpiontService save size is {}",  saveSizeArray);
	}
}
